home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / gcc / gcc261c.zoo / objects / GapArrayPrivate.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-18  |  2.8 KB  |  90 lines

  1. /* GapArray definitions for the use of subclass implementations
  2.    Copyright (C) 1993,1994 Free Software Foundation, Inc.
  3.  
  4.    Written by:  R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
  5.    Date: May 1993
  6.    Copyright (C) 1993,1994 Kresten Krab Thorup <krab@iesd.auc.dk>
  7.    Dept. of Mathematics and Computer Science, Aalborg U., Denmark
  8.  
  9.    This file is part of the GNU Objective C Class Library.
  10.  
  11.    This library is free software; you can redistribute it and/or
  12.    modify it under the terms of the GNU Library General Public
  13.    License as published by the Free Software Foundation; either
  14.    version 2 of the License, or (at your option) any later version.
  15.    
  16.    This library is distributed in the hope that it will be useful,
  17.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  19.    Library General Public License for more details.
  20.  
  21.    You should have received a copy of the GNU Library General Public
  22.    License along with this library; if not, write to the Free
  23.    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. */ 
  25.  
  26. #ifndef __GapArrayPrivate_h_INCLUDE_GNU
  27. #define __GapArrayPrivate_h_INCLUDE_GNU
  28.  
  29. #include <objects/stdobjects.h>
  30. #include <objects/ArrayPrivate.h>
  31. #include <assert.h>
  32.  
  33. #define GAP_TO_BASIC(INDEX)              \
  34.   ({ unsigned int __idx = (INDEX);       \
  35.        __idx >= self->_gap_start         \
  36.      ? __idx+self->_gap_size : __idx; })
  37.  
  38. #define BASIC_TO_GAP(INDEX)              \
  39.   ({ unsigned int __idx = (INDEX);       \
  40.        __idx < self->_gap_start          \
  41.      ? __idx : __idx-self->_gap_size; })
  42.  
  43. static inline void
  44. gapMoveGapTo (GapArray* self, unsigned index)
  45. {
  46.   int i;
  47.   assert (index <= self->_capacity);
  48.   if (index < self->_gap_start)
  49.     {
  50. #ifndef STABLE_MEMCPY      
  51.       int b = index + self->_gap_size;
  52.       for (i = self->_gap_start + self->_gap_size - 1; i >= b; i--)
  53.     self->_contents_array[i] = self->_contents_array[i - self->_gap_size];
  54. #else
  55.       memcpy (self->_contents_array + index + self->_gap_size,
  56.           self->_contents_array + index,
  57.           self->_gap_start - index)
  58. #endif
  59.     }
  60.   else
  61.     {
  62. #ifndef STABLE_MEMCPY
  63.       for(i = self->_gap_start; i != index; i++)
  64.     self->_contents_array[i] = self->_contents_array[i - self->_gap_size];
  65. #else
  66.       memcpy (self->_contents_array + self->_gap_start,
  67.           self->_contents_array + self->_gap_start + self->_gap_size,
  68.           index - self->_gap_start);
  69. #endif
  70.     }
  71.   self->_gap_start = index;
  72. }
  73.  
  74. static inline void
  75. gapMakeHoleAt(GapArray *self, unsigned index)
  76. {
  77.   gapMoveGapTo (self, index);
  78.   self->_gap_start += 1;
  79.   self->_gap_size -= 1;
  80. }
  81.  
  82. static inline void
  83. gapFillHoleAt(GapArray *self, unsigned index)
  84. {
  85.   gapMoveGapTo (self, index);
  86.   self->_gap_size += 1;
  87. }
  88.  
  89. #endif /* __GapArrayPrivate_h_INCLUDE_GNU */
  90.